﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DataAnalyse
{
    /// <summary>
    /// DataTabControl.xaml 的交互逻辑
    /// </summary>
    public partial class DataTabControl : TabControl
    {
        private TabItem _contextMenuSource;
        public DataTabControl()
        {
            InitializeComponent();
        }

        private void btnTabItemClose_Click(object sender, RoutedEventArgs e)
        {
            var btn = sender as Button;
            var tmplParent = (btn.Parent as Grid).TemplatedParent;
            var tabItem = tmplParent as TabItem;
            if (this.Items.Count == 1) return;
            CloseTabItem(tabItem);
        }

        #region 关闭TabItem
        /// <summary>
        /// 关闭TabItem
        /// </summary>
        private void CloseTabItem(TabItem tabItem)
        {
            if (tabItem.Content is WebBrowser)
            {
                var content = tabItem.Content as WebBrowser;
                if (content != null)
                {
                    content.Dispose();
                }
                tabItem.Content = null;
            }
            this.Items.Remove(tabItem);
        }
        #endregion
    }
}
